home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / src / gdb-4.12 / gdb / blockfra.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-03  |  22.6 KB  |  822 lines

  1. /* Get info from stack frames;
  2.    convert between frames, blocks, functions and pc values.
  3.    Copyright 1986, 1987, 1988, 1989, 1991 Free Software Foundation, Inc.
  4.  
  5. This file is part of GDB.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #include "defs.h"
  22. #include "symtab.h"
  23. #include "bfd.h"
  24. #include "symfile.h"
  25. #include "objfiles.h"
  26. #include "frame.h"
  27. #include "gdbcore.h"
  28. #include "value.h"        /* for read_register */
  29. #include "target.h"        /* for target_has_stack */
  30. #include "inferior.h"        /* for read_pc */
  31.  
  32. /* Is ADDR inside the startup file?  Note that if your machine
  33.    has a way to detect the bottom of the stack, there is no need
  34.    to call this function from FRAME_CHAIN_VALID; the reason for
  35.    doing so is that some machines have no way of detecting bottom
  36.    of stack. 
  37.  
  38.    A PC of zero is always considered to be the bottom of the stack. */
  39.  
  40. int
  41. inside_entry_file (addr)
  42.      CORE_ADDR addr;
  43. {
  44.   if (addr == 0)
  45.     return 1;
  46.   if (symfile_objfile == 0)
  47.     return 0;
  48. #if CALL_DUMMY_LOCATION == AT_ENTRY_POINT
  49.   /* Do not stop backtracing if the pc is in the call dummy
  50.      at the entry point.  */
  51.   if (PC_IN_CALL_DUMMY (addr, 0, 0))
  52.     return 0;
  53. #endif
  54.   return (addr >= symfile_objfile -> ei.entry_file_lowpc &&
  55.       addr <  symfile_objfile -> ei.entry_file_highpc);
  56. }
  57.  
  58. /* Test a specified PC value to see if it is in the range of addresses
  59.    that correspond to the main() function.  See comments above for why
  60.    we might want to do this.
  61.  
  62.    Typically called from FRAME_CHAIN_VALID.
  63.  
  64.    A PC of zero is always considered to be the bottom of the stack. */
  65.  
  66. int
  67. inside_main_func (pc)
  68. CORE_ADDR pc;
  69. {
  70.   if (pc == 0)
  71.     return 1;
  72.   if (symfile_objfile == 0)
  73.     return 0;
  74.   return (symfile_objfile -> ei.main_func_lowpc  <= pc &&
  75.       symfile_objfile -> ei.main_func_highpc > pc);
  76. }
  77.  
  78. /* Test a specified PC value to see if it is in the range of addresses
  79.    that correspond to the process entry point function.  See comments
  80.    in objfiles.h for why we might want to do this.
  81.  
  82.    Typically called from FRAME_CHAIN_VALID.
  83.  
  84.    A PC of zero is always considered to be the bottom of the stack. */
  85.  
  86. int
  87. inside_entry_func (pc)
  88. CORE_ADDR pc;
  89. {
  90.   if (pc == 0)
  91.     return 1;
  92.   if (symfile_objfile == 0)
  93.     return 0;
  94. #if CALL_DUMMY_LOCATION == AT_ENTRY_POINT
  95.   /* Do not stop backtracing if the pc is in the call dummy
  96.      at the entry point.  */
  97.   if (PC_IN_CALL_DUMMY (pc, 0, 0))
  98.     return 0;
  99. #endif
  100.   return (symfile_objfile -> ei.entry_func_lowpc  <= pc &&
  101.       symfile_objfile -> ei.entry_func_highpc > pc);
  102. }
  103.  
  104. /* Address of innermost stack frame (contents of FP register) */
  105.  
  106. static FRAME current_frame;
  107.  
  108. /*
  109.  * Cache for frame addresses already read by gdb.  Valid only while
  110.  * inferior is stopped.  Control variables for the frame cache should
  111.  * be local to this module.
  112.  */
  113. struct obstack frame_cache_obstack;
  114.  
  115. /* Return the innermost (currently executing) stack frame.  */
  116.  
  117. FRAME
  118. get_current_frame ()
  119. {
  120.   /* We assume its address is kept in a general register;
  121.      param.h says which register.  */
  122.  
  123.   return current_frame;
  124. }
  125.  
  126. void
  127. set_current_frame (frame)
  128.      FRAME frame;
  129. {
  130.   current_frame = frame;
  131. }
  132.  
  133. FRAME
  134. create_new_frame (addr, pc)
  135.      FRAME_ADDR addr;
  136.      CORE_ADDR pc;
  137. {
  138.   struct frame_info *fci;    /* Same type as FRAME */
  139.   char *name;
  140.  
  141.   fci = (struct frame_info *)
  142.     obstack_alloc (&frame_cache_obstack,
  143.            sizeof (struct frame_info));
  144.  
  145.   /* Arbitrary frame */
  146.   fci->next = (struct frame_info *) 0;
  147.   fci->prev = (struct frame_info *) 0;
  148.   fci->frame = addr;
  149.   fci->pc = pc;
  150.   find_pc_partial_function (pc, &name, (CORE_ADDR *)NULL,(CORE_ADDR *)NULL);
  151.   fci->signal_handler_caller = IN_SIGTRAMP (fci->pc, name);
  152.  
  153. #ifdef INIT_EXTRA_FRAME_INFO
  154.   INIT_EXTRA_FRAME_INFO (0, fci);
  155. #endif
  156.  
  157.   return fci;
  158. }
  159.  
  160. /* Return the frame that called FRAME.
  161.    If FRAME is the original frame (it has no caller), return 0.  */
  162.  
  163. FRAME
  164. get_prev_frame (frame)
  165.      FRAME frame;
  166. {
  167.   /* We're allowed to know that FRAME and "struct frame_info *" are
  168.      the same */
  169.   return get_prev_frame_info (frame);
  170. }
  171.  
  172. /* Return the frame that FRAME calls (0 if FRAME is the innermost
  173.    frame).  */
  174.  
  175. FRAME
  176. get_next_frame (frame)
  177.      FRAME frame;
  178. {
  179.   /* We're allowed to know that FRAME and "struct frame_info *" are
  180.      the same */
  181.   return frame->next;
  182. }
  183.  
  184. /*
  185.  * Flush the entire frame cache.
  186.  */
  187. void
  188. flush_cached_frames ()
  189. {
  190.   /* Since we can't really be sure what the first object allocated was */
  191.   obstack_free (&frame_cache_obstack, 0);
  192.   obstack_init (&frame_cache_obstack);
  193.  
  194.   current_frame = (struct frame_info *) 0; /* Invalidate cache */
  195. }
  196.  
  197. /* Flush the frame cache, and start a new one if necessary.  */
  198. void
  199. reinit_frame_cache ()
  200. {
  201.   flush_cached_frames ();
  202.   if (target_has_stack)
  203.     {
  204.       set_current_frame (create_new_frame (read_fp (), read_pc ()));
  205.       select_frame (get_current_frame (), 0);
  206.     }
  207.   else
  208.     {
  209.       set_current_frame (0);
  210.       select_frame ((FRAME) 0, -1);
  211.     }
  212. }
  213.  
  214. /* Return a structure containing various interesting information
  215.    about a specified stack frame.  */
  216. /* How do I justify including this function?  Well, the FRAME
  217.    identifier format has gone through several changes recently, and
  218.    it's not completely inconceivable that it could happen again.  If
  219.    it does, have this routine around will help */
  220.  
  221. struct frame_info *
  222. get_frame_info (frame)
  223.      FRAME frame;
  224. {
  225.   return frame;
  226. }
  227.  
  228. /* If a machine allows frameless functions, it should define a macro
  229.    FRAMELESS_FUNCTION_INVOCATION(FI, FRAMELESS) in param.h.  FI is the struct
  230.    frame_info for the frame, and FRAMELESS should be set to nonzero
  231.    if it represents a frameless function invocation.  */
  232.  
  233. /* Return nonzero if the function for this frame lacks a prologue.  Many
  234.    machines can define FRAMELESS_FUNCTION_INVOCATION to just call this
  235.    function.  */
  236.  
  237. int
  238. frameless_look_for_prologue (frame)
  239.      FRAME frame;
  240. {
  241.   CORE_ADDR func_start, after_prologue;
  242.   func_start = (get_pc_function_start (frame->pc) +
  243.         FUNCTION_START_OFFSET);
  244.   if (func_start)
  245.     {
  246.       after_prologue = func_start;
  247. #ifdef SKIP_PROLOGUE_FRAMELESS_P
  248.       /* This is faster, since only care whether there *is* a prologue,
  249.      not how long it is.  */
  250.       SKIP_PROLOGUE_FRAMELESS_P (after_prologue);
  251. #else
  252.       SKIP_PROLOGUE (after_prologue);
  253. #endif
  254.       return after_prologue == func_start;
  255.     }
  256.   else
  257.     /* If we can't find the start of the function, we don't really
  258.        know whether the function is frameless, but we should be able
  259.        to get a reasonable (i.e. best we can do under the
  260.        circumstances) backtrace by saying that it isn't.  */
  261.     return 0;
  262. }
  263.  
  264. /* Default a few macros that people seldom redefine.  */
  265.  
  266. #if !defined (INIT_FRAME_PC)
  267. #define INIT_FRAME_PC(fromleaf, prev) \
  268.   prev->pc = (fromleaf ? SAVED_PC_AFTER_CALL (prev->next) : \
  269.           prev->next ? FRAME_SAVED_PC (prev->next) : read_pc ());
  270. #endif
  271.  
  272. #ifndef FRAME_CHAIN_COMBINE
  273. #define    FRAME_CHAIN_COMBINE(chain, thisframe) (chain)
  274. #endif
  275.  
  276. /* Return a structure containing various interesting information
  277.    about the frame that called NEXT_FRAME.  Returns NULL
  278.    if there is no such frame.  */
  279.  
  280. struct frame_info *
  281. get_prev_frame_info (next_frame)
  282.      FRAME next_frame;
  283. {
  284.   FRAME_ADDR address = 0;
  285.   struct frame_info *prev;
  286.   int fromleaf = 0;
  287.   char *name;
  288.  
  289.   /* If the requested entry is in the cache, return it.
  290.      Otherwise, figure out what the address should be for the entry
  291.      we're about to add to the cache. */
  292.  
  293.   if (!next_frame)
  294.     {
  295. #if 0
  296.       /* This screws value_of_variable, which just wants a nice clean
  297.      NULL return from block_innermost_frame if there are no frames.
  298.      I don't think I've ever seen this message happen otherwise.
  299.      And returning NULL here is a perfectly legitimate thing to do.  */
  300.       if (!current_frame)
  301.     {
  302.       error ("You haven't set up a process's stack to examine.");
  303.     }
  304. #endif
  305.  
  306.       return current_frame;
  307.     }
  308.  
  309.   /* If we have the prev one, return it */
  310.   if (next_frame->prev)
  311.     return next_frame->prev;
  312.  
  313.   /* On some machines it is possible to call a function without
  314.      setting up a stack frame for it.  On these machines, we
  315.      define this macro to take two args; a frameinfo pointer
  316.      identifying a frame and a variable to set or clear if it is
  317.      or isn't leafless.  */
  318. #ifdef FRAMELESS_FUNCTION_INVOCATION
  319.   /* Still don't want to worry about this except on the innermost
  320.      frame.  This macro will set FROMLEAF if NEXT_FRAME is a
  321.      frameless function invocation.  */
  322.   if (!(next_frame->next))
  323.     {
  324.       FRAMELESS_FUNCTION_INVOCATION (next_frame, fromleaf);
  325.       if (fromleaf)
  326.     address = next_frame->frame;
  327.     }
  328. #endif
  329.  
  330.   if (!fromleaf)
  331.     {
  332.       /* Two macros defined in tm.h specify the machine-dependent
  333.      actions to be performed here.
  334.      First, get the frame's chain-pointer.
  335.      If that is zero, the frame is the outermost frame or a leaf
  336.      called by the outermost frame.  This means that if start
  337.      calls main without a frame, we'll return 0 (which is fine
  338.      anyway).
  339.  
  340.      Nope; there's a problem.  This also returns when the current
  341.      routine is a leaf of main.  This is unacceptable.  We move
  342.      this to after the ffi test; I'd rather have backtraces from
  343.      start go curfluy than have an abort called from main not show
  344.      main.  */
  345.       address = FRAME_CHAIN (next_frame);
  346.       if (!FRAME_CHAIN_VALID (address, next_frame))
  347.     return 0;
  348.       address = FRAME_CHAIN_COMBINE (address, next_frame);
  349.     }
  350.   if (address == 0)
  351.     return 0;
  352.  
  353.   prev = (struct frame_info *)
  354.     obstack_alloc (&frame_cache_obstack,
  355.            sizeof (struct frame_info));
  356.  
  357.   if (next_frame)
  358.     next_frame->prev = prev;
  359.   prev->next = next_frame;
  360.   prev->prev = (struct frame_info *) 0;
  361.   prev->frame = address;
  362.   prev->signal_handler_caller = 0;
  363.  
  364. /* This change should not be needed, FIXME!  We should
  365.    determine whether any targets *need* INIT_FRAME_PC to happen
  366.    after INIT_EXTRA_FRAME_INFO and come up with a simple way to
  367.    express what goes on here.
  368.  
  369.       INIT_EXTRA_FRAME_INFO is called from two places: create_new_frame
  370.               (where the PC is already set up) and here (where it isn't).
  371.       INIT_FRAME_PC is only called from here, always after
  372.               INIT_EXTRA_FRAME_INFO.
  373.    
  374.    The catch is the MIPS, where INIT_EXTRA_FRAME_INFO requires the PC
  375.    value (which hasn't been set yet).  Some other machines appear to
  376.    require INIT_EXTRA_FRAME_INFO before they can do INIT_FRAME_PC.  Phoo.
  377.  
  378.    We shouldn't need INIT_FRAME_PC_FIRST to add more complication to
  379.    an already overcomplicated part of GDB.   gnu@cygnus.com, 15Sep92.
  380.  
  381.    To answer the question, yes the sparc needs INIT_FRAME_PC after
  382.    INIT_EXTRA_FRAME_INFO.  Suggested scheme:
  383.  
  384.    SETUP_INNERMOST_FRAME()
  385.      Default version is just create_new_frame (read_fp ()),
  386.      read_pc ()).  Machines with extra frame info would do that (or the
  387.      local equivalent) and then set the extra fields.
  388.    SETUP_ARBITRARY_FRAME(argc, argv)
  389.      Only change here is that create_new_frame would no longer init extra
  390.      frame info; SETUP_ARBITRARY_FRAME would have to do that.
  391.    INIT_PREV_FRAME(fromleaf, prev)
  392.      Replace INIT_EXTRA_FRAME_INFO and INIT_FRAME_PC.
  393.    std_frame_pc(fromleaf, prev)
  394.      This is the default setting for INIT_PREV_FRAME.  It just does what
  395.      the default INIT_FRAME_PC does.  Some machines will call it from
  396.      INIT_PREV_FRAME (either at the beginning, the end, or in the middle).
  397.      Some machines won't use it.
  398.    kingdon@cygnus.com, 13Apr93.  */
  399.  
  400. #ifdef INIT_FRAME_PC_FIRST
  401.   INIT_FRAME_PC_FIRST (fromleaf, prev);
  402. #endif
  403.  
  404. #ifdef INIT_EXTRA_FRAME_INFO
  405.   INIT_EXTRA_FRAME_INFO(fromleaf, prev);
  406. #endif
  407.  
  408.   /* This entry is in the frame queue now, which is good since
  409.      FRAME_SAVED_PC may use that queue to figure out it's value
  410.      (see tm-sparc.h).  We want the pc saved in the inferior frame. */
  411.   INIT_FRAME_PC(fromleaf, prev);
  412.  
  413.   find_pc_partial_function (prev->pc, &name,
  414.                 (CORE_ADDR *)NULL,(CORE_ADDR *)NULL);
  415.   if (IN_SIGTRAMP (prev->pc, name))
  416.     prev->signal_handler_caller = 1;
  417.  
  418.   return prev;
  419. }
  420.  
  421. CORE_ADDR
  422. get_frame_pc (frame)
  423.      FRAME frame;
  424. {
  425.   struct frame_info *fi;
  426.   fi = get_frame_info (frame);
  427.   return fi->pc;
  428. }
  429.  
  430. #if defined (FRAME_FIND_SAVED_REGS)
  431. /* Find the addresses in which registers are saved in FRAME.  */
  432.  
  433. void
  434. get_frame_saved_regs (frame_info_addr, saved_regs_addr)
  435.      struct frame_info *frame_info_addr;
  436.      struct frame_saved_regs *saved_regs_addr;
  437. {
  438.   FRAME_FIND_SAVED_REGS (frame_info_addr, *saved_regs_addr);
  439. }
  440. #endif
  441.  
  442. /* Return the innermost lexical block in execution
  443.    in a specified stack frame.  The frame address is assumed valid.  */
  444.  
  445. struct block *
  446. get_frame_block (frame)
  447.      FRAME frame;
  448. {
  449.   struct frame_info *fi;
  450.   CORE_ADDR pc;
  451.  
  452.   fi = get_frame_info (frame);
  453.  
  454.   pc = fi->pc;
  455.   if (fi->next != 0 && fi->next->signal_handler_caller == 0)
  456.     /* We are not in the innermost frame and we were not interrupted
  457.        by a signal.  We need to subtract one to get the correct block,
  458.        in case the call instruction was the last instruction of the block.
  459.        If there are any machines on which the saved pc does not point to
  460.        after the call insn, we probably want to make fi->pc point after
  461.        the call insn anyway.  */
  462.     --pc;
  463.   return block_for_pc (pc);
  464. }
  465.  
  466. struct block *
  467. get_current_block ()
  468. {
  469.   return block_for_pc (read_pc ());
  470. }
  471.  
  472. CORE_ADDR
  473. get_pc_function_start (pc)
  474.      CORE_ADDR pc;
  475. {
  476.   register struct block *bl;
  477.   register struct symbol *symbol;
  478.   register struct minimal_symbol *msymbol;
  479.   CORE_ADDR fstart;
  480.  
  481.   if ((bl = block_for_pc (pc)) != NULL &&
  482.       (symbol = block_function (bl)) != NULL)
  483.     {
  484.       bl = SYMBOL_BLOCK_VALUE (symbol);
  485.       fstart = BLOCK_START (bl);
  486.     }
  487.   else if ((msymbol = lookup_minimal_symbol_by_pc (pc)) != NULL)
  488.     {
  489.       fstart = SYMBOL_VALUE_ADDRESS (msymbol);
  490.     }
  491.   else
  492.     {
  493.       fstart = 0;
  494.     }
  495.   return (fstart);
  496. }
  497.  
  498. /* Return the symbol for the function executing in frame FRAME.  */
  499.  
  500. struct symbol *
  501. get_frame_function (frame)
  502.      FRAME frame;
  503. {
  504.   register struct block *bl = get_frame_block (frame);
  505.   if (bl == 0)
  506.     return 0;
  507.   return block_function (bl);
  508. }
  509.  
  510. /* Return the blockvector immediately containing the innermost lexical block
  511.    containing the specified pc value, or 0 if there is none.
  512.    PINDEX is a pointer to the index value of the block.  If PINDEX
  513.    is NULL, we don't pass this information back to the caller.  */
  514.  
  515. struct blockvector *
  516. blockvector_for_pc (pc, pindex)
  517.      register CORE_ADDR pc;
  518.      int *pindex;
  519. {
  520.   register struct block *b;
  521.   register int bot, top, half;
  522.   register struct symtab *s;
  523.   struct blockvector *bl;
  524.  
  525.   /* First search all symtabs for one whose file contains our pc */
  526.   s = find_pc_symtab (pc);
  527.   if (s == 0)
  528.     return 0;
  529.  
  530.   bl = BLOCKVECTOR (s);
  531.   b = BLOCKVECTOR_BLOCK (bl, 0);
  532.  
  533.   /* Then search that symtab for the smallest block that wins.  */
  534.   /* Use binary search to find the last block that starts before PC.  */
  535.  
  536.   bot = 0;
  537.   top = BLOCKVECTOR_NBLOCKS (bl);
  538.  
  539.   while (top - bot > 1)
  540.     {
  541.       half = (top - bot + 1) >> 1;
  542.       b = BLOCKVECTOR_BLOCK (bl, bot + half);
  543.       if (BLOCK_START (b) <= pc)
  544.     bot += half;
  545.       else
  546.     top = bot + half;
  547.     }
  548.  
  549.   /* Now search backward for a block that ends after PC.  */
  550.  
  551.   while (bot >= 0)
  552.     {
  553.       b = BLOCKVECTOR_BLOCK (bl, bot);
  554.       if (BLOCK_END (b) > pc)
  555.     {
  556.       if (pindex)
  557.         *pindex = bot;
  558.       return bl;
  559.     }
  560.       bot--;
  561.     }
  562.  
  563.   return 0;
  564. }
  565.  
  566. /* Return the innermost lexical block containing the specified pc value,
  567.    or 0 if there is none.  */
  568.  
  569. struct block *
  570. block_for_pc (pc)
  571.      register CORE_ADDR pc;
  572. {
  573.   register struct blockvector *bl;
  574.   int index;
  575.  
  576.   bl = blockvector_for_pc (pc, &index);
  577.   if (bl)
  578.     return BLOCKVECTOR_BLOCK (bl, index);
  579.   return 0;
  580. }
  581.  
  582. /* Return the function containing pc value PC.
  583.    Returns 0 if function is not known.  */
  584.  
  585. struct symbol *
  586. find_pc_function (pc)
  587.      CORE_ADDR pc;
  588. {
  589.   register struct block *b = block_for_pc (pc);
  590.   if (b == 0)
  591.     return 0;
  592.   return block_function (b);
  593. }
  594.  
  595. /* These variables are used to cache the most recent result
  596.  * of find_pc_partial_function. */
  597.  
  598. static CORE_ADDR cache_pc_function_low = 0;
  599. static CORE_ADDR cache_pc_function_high = 0;
  600. static char *cache_pc_function_name = 0;
  601.  
  602. /* Clear cache, e.g. when symbol table is discarded. */
  603.  
  604. void
  605. clear_pc_function_cache()
  606. {
  607.   cache_pc_function_low = 0;
  608.   cache_pc_function_high = 0;
  609.   cache_pc_function_name = (char *)0;
  610. }
  611.  
  612. /* Finds the "function" (text symbol) that is smaller than PC but
  613.    greatest of all of the potential text symbols.  Sets *NAME and/or
  614.    *ADDRESS conditionally if that pointer is non-null.  If ENDADDR is
  615.    non-null, then set *ENDADDR to be the end of the function
  616.    (exclusive), but passing ENDADDR as non-null means that the
  617.    function might cause symbols to be read.  This function either
  618.    succeeds or fails (not halfway succeeds).  If it succeeds, it sets
  619.    *NAME, *ADDRESS, and *ENDADDR to real information and returns 1.
  620.    If it fails, it sets *NAME, *ADDRESS, and *ENDADDR to zero
  621.    and returns 0.  */
  622.  
  623. int
  624. find_pc_partial_function (pc, name, address, endaddr)
  625.      CORE_ADDR pc;
  626.      char **name;
  627.      CORE_ADDR *address;
  628.      CORE_ADDR *endaddr;
  629. {
  630.   struct partial_symtab *pst;
  631.   struct symbol *f;
  632.   struct minimal_symbol *msymbol;
  633.   struct partial_symbol *psb;
  634.   struct obj_section *sec;
  635.  
  636.   if (pc >= cache_pc_function_low && pc < cache_pc_function_high)
  637.     goto return_cached_value;
  638.  
  639.   /* If sigtramp is in the u area, it counts as a function (especially
  640.      important for step_1).  */
  641. #if defined SIGTRAMP_START
  642.   if (IN_SIGTRAMP (pc, (char *)NULL))
  643.     {
  644.       cache_pc_function_low = SIGTRAMP_START;
  645.       cache_pc_function_high = SIGTRAMP_END;
  646.       cache_pc_function_name = "<sigtramp>";
  647.  
  648.       goto return_cached_value;
  649.     }
  650. #endif
  651.  
  652.   msymbol = lookup_minimal_symbol_by_pc (pc);
  653.   pst = find_pc_psymtab (pc);
  654.   if (pst)
  655.     {
  656.       /* Need to read the symbols to get a good value for the end address.  */
  657.       if (endaddr != NULL && !pst->readin)
  658.     {
  659.       /* Need to get the terminal in case symbol-reading produces
  660.          output.  */
  661.       target_terminal_ours_for_output ();
  662.       PSYMTAB_TO_SYMTAB (pst);
  663.     }
  664.  
  665.       if (pst->readin)
  666.     {
  667.       /* Checking whether the msymbol has a larger value is for the
  668.          "pathological" case mentioned in print_frame_info.  */
  669.       f = find_pc_function (pc);
  670.       if (f != NULL
  671.           && (msymbol == NULL
  672.           || (BLOCK_START (SYMBOL_BLOCK_VALUE (f))
  673.               >= SYMBOL_VALUE_ADDRESS (msymbol))))
  674.         {
  675.           cache_pc_function_low = BLOCK_START (SYMBOL_BLOCK_VALUE (f));
  676.           cache_pc_function_high = BLOCK_END (SYMBOL_BLOCK_VALUE (f));
  677.           cache_pc_function_name = SYMBOL_NAME (f);
  678.           goto return_cached_value;
  679.         }
  680.     }
  681.       else
  682.     {
  683.       /* Now that static symbols go in the minimal symbol table, perhaps
  684.          we could just ignore the partial symbols.  But at least for now
  685.          we use the partial or minimal symbol, whichever is larger.  */
  686.       psb = find_pc_psymbol (pst, pc);
  687.  
  688.       if (psb
  689.           && (msymbol == NULL ||
  690.           (SYMBOL_VALUE_ADDRESS (psb)
  691.            >= SYMBOL_VALUE_ADDRESS (msymbol))))
  692.         {
  693.           /* This case isn't being cached currently. */
  694.           if (address)
  695.         *address = SYMBOL_VALUE_ADDRESS (psb);
  696.           if (name)
  697.         *name = SYMBOL_NAME (psb);
  698.           /* endaddr non-NULL can't happen here.  */
  699.           return 1;
  700.         }
  701.     }
  702.     }
  703.  
  704.   /* Not in the normal symbol tables, see if the pc is in a known section.
  705.      If it's not, then give up.  This ensures that anything beyond the end
  706.      of the text seg doesn't appear to be part of the last function in the
  707.      text segment.  */
  708.  
  709.   sec = find_pc_section (pc);
  710.  
  711.   if (!sec)
  712.     msymbol = NULL;
  713.  
  714.   /* Must be in the minimal symbol table.  */
  715.   if (msymbol == NULL)
  716.     {
  717.       /* No available symbol.  */
  718.       if (name != NULL)
  719.     *name = 0;
  720.       if (address != NULL)
  721.     *address = 0;
  722.       if (endaddr != NULL)
  723.     *endaddr = 0;
  724.       return 0;
  725.     }
  726.  
  727.   /* See if we're in a transfer table for Sun shared libs.  */
  728.  
  729.   if (msymbol -> type == mst_text)
  730.     cache_pc_function_low = SYMBOL_VALUE_ADDRESS (msymbol);
  731.   else
  732.     /* It is a transfer table for Sun shared libraries.  */
  733.     cache_pc_function_low = pc - FUNCTION_START_OFFSET;
  734.  
  735.   cache_pc_function_name = SYMBOL_NAME (msymbol);
  736.  
  737.   /* Use the lesser of the next minimal symbol, or the end of the section, as
  738.      the end of the function.  */
  739.  
  740.   if (SYMBOL_NAME (msymbol + 1) != NULL
  741.       && SYMBOL_VALUE_ADDRESS (msymbol + 1) < sec->endaddr)
  742.     cache_pc_function_high = SYMBOL_VALUE_ADDRESS (msymbol + 1);
  743.   else
  744.     /* We got the start address from the last msymbol in the objfile.
  745.        So the end address is the end of the section.  */
  746.     cache_pc_function_high = sec->endaddr;
  747.  
  748.  return_cached_value:
  749.   if (address)
  750.     *address = cache_pc_function_low;
  751.   if (name)
  752.     *name = cache_pc_function_name;
  753.   if (endaddr)
  754.     *endaddr = cache_pc_function_high;
  755.   return 1;
  756. }
  757.  
  758. /* Return the innermost stack frame executing inside of BLOCK,
  759.    or NULL if there is no such frame.  If BLOCK is NULL, just return NULL.  */
  760.  
  761. FRAME
  762. block_innermost_frame (block)
  763.      struct block *block;
  764. {
  765.   struct frame_info *fi;
  766.   register FRAME frame;
  767.   register CORE_ADDR start;
  768.   register CORE_ADDR end;
  769.  
  770.   if (block == NULL)
  771.     return NULL;
  772.  
  773.   start = BLOCK_START (block);
  774.   end = BLOCK_END (block);
  775.  
  776.   frame = 0;
  777.   while (1)
  778.     {
  779.       frame = get_prev_frame (frame);
  780.       if (frame == 0)
  781.     return 0;
  782.       fi = get_frame_info (frame);
  783.       if (fi->pc >= start && fi->pc < end)
  784.     return frame;
  785.     }
  786. }
  787.  
  788. #ifdef SIGCONTEXT_PC_OFFSET
  789. /* Get saved user PC for sigtramp from sigcontext for BSD style sigtramp.  */
  790.  
  791. CORE_ADDR
  792. sigtramp_saved_pc (frame)
  793.      FRAME frame;
  794. {
  795.   CORE_ADDR sigcontext_addr;
  796.   char buf[TARGET_PTR_BIT / TARGET_CHAR_BIT];
  797.   int ptrbytes = TARGET_PTR_BIT / TARGET_CHAR_BIT;
  798.   int sigcontext_offs = (2 * TARGET_INT_BIT) / TARGET_CHAR_BIT;
  799.  
  800.   /* Get sigcontext address, it is the third parameter on the stack.  */
  801.   if (frame->next)
  802.     sigcontext_addr = read_memory_integer (FRAME_ARGS_ADDRESS (frame->next)
  803.                         + FRAME_ARGS_SKIP + sigcontext_offs,
  804.                        ptrbytes);
  805.   else
  806.     sigcontext_addr = read_memory_integer (read_register (SP_REGNUM)
  807.                         + sigcontext_offs,
  808.                        ptrbytes);
  809.  
  810.   /* Don't cause a memory_error when accessing sigcontext in case the stack
  811.      layout has changed or the stack is corrupt.  */
  812.   target_read_memory (sigcontext_addr + SIGCONTEXT_PC_OFFSET, buf, ptrbytes);
  813.   return extract_unsigned_integer (buf, ptrbytes);
  814. }
  815. #endif /* SIGCONTEXT_PC_OFFSET */
  816.  
  817. void
  818. _initialize_blockframe ()
  819. {
  820.   obstack_init (&frame_cache_obstack);
  821. }
  822.